﻿using 创建者模式.factory;

namespace 创建者模式
{
    internal class Program
    {
        static void Main(string[] args)
        {

            //var apple = SimpleFactory.CreateFruit("apple");
            //apple.Show();

            //var pear = SimpleFactory.CreateFruit("pear");
            //pear.Show();

            //var apple1 = new AppleFactory().CreateFruit();
            //apple1.Show();

            //var pear1 = new PearFactory().CreateFruit();
            //pear1.Show();

            //IFruitFactory appleFacotry = new AppleFactory();
            //var apple2 = appleFacotry.CreateFruit();
            //apple2.Show();

            //IFruitFactory pearFacotry = new PearFactory();
            //var pear2 = pearFacotry.CreateFruit();
            //pear2.Show();

            //// 创建者模式
            //var builder = new MilkTea.MilkBuilder();
            //builder.SetType("milkTea").SetPearl("5").SetSize(13).SetIce("has Ice");
            //var tea = builder.Build();
            //Console.WriteLine( tea.ToString() );


            //prototype 
            ProtoTypeObj proto = new ProtoTypeObj() {
                Id = 1,
                Name = "test",
                HouselInfo = new HouselInfo()
                {
                    HouseAge =18,
                    HouseName = "Mei jing",
                    HouseNo ="001"
                }
            };

            var obj = proto.Clone();
            var protoCloneObj = obj as ProtoTypeObj;
            if(protoCloneObj != null)
            {
                protoCloneObj.Name = "XXX";
                protoCloneObj.Id = 100;
                protoCloneObj.HouselInfo.HouseName = "**********";
                protoCloneObj.HouselInfo.HouseAge = 30;
                Console.WriteLine("深拷贝的对象----------------------->");
                Console.WriteLine(protoCloneObj.ToString());
            }
            Console.WriteLine("原始对象-------------------------->");
            Console.WriteLine( proto.ToString() );

            Console.ReadKey();
               
        }
    }
}